package jdbc;

import java.sql.Connection;  
import java.sql.DriverManager;  
import java.sql.ResultSet;  
import java.sql.SQLException;
import java.sql.Statement;

public class DbManager {
	
	Connection conn;
	Statement stm;
	
	public Connection getConnection() throws SQLException {
	try {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/felight","root","");
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
		System.out.println("Error : " + e);
	}
	return null;
	}
	
	public void  select() {
		try {
			stm = conn.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Error : " + e);
		}
	}
	
	public void  insert (String query) {
		//System.out.println(query);
		try {
			stm = conn.createStatement();
			stm.executeUpdate(query);
			System.out.println("1 row inserted successfully");
			
		} catch (SQLException e1) {
			e1.printStackTrace();
			System.out.println("Error : " + e1);
		}
	}
	
	public void  delete (String query) {
		//System.out.println(query);
		try {
			stm = conn.createStatement();
			stm.executeUpdate(query);
			System.out.println("Row/s deleted successfully");
			
		} catch (SQLException e1) {
			e1.printStackTrace();
			System.out.println("Error : " + e1);
		}
	}
	
	public void  update (String query) {
		//System.out.println(query);
		try {
			stm = conn.createStatement();
			stm.executeUpdate(query);
			System.out.println("Row/s updated successfully");
			
		} catch (SQLException e1) {
			e1.printStackTrace();
			System.out.println("Error : " + e1);
		}
	}
	
	public void closeConnection() throws SQLException {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Error : " + e);
		}
		
	}
}

